import { customRequestNew } from '@/common/newUpload.js'

// 新版上传组件使用
export default {
  data() {
    return {}
  },
  mounted() { },
  methods: {
    /**
  * 新版上传组件使用
  * @param {*} action
  * @param {*} dir
  * @param {*} that
  */
    PUpLoadFileCustomRequestEvent(action, dir, that) {
      // console.log('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2', action, dir, that);
      return customRequestNew(action, dir, that)
    },
    addEllipsis(Str, maxLength=9) {
      let res = Str
      if(this.$IS.isNullOrUnDef(res) || this.$IS.isEmpty(Str)){
        return ''
      }
      if(!this.$IS.isString(Str)){
        res = `${Str}`
      }
      if (Str.length > maxLength) {
        res = Str.substring(0, maxLength) + '...';
      }
      return res
    },
    /**
     * @param {Object} BKInfo 处理函数 { '1200':()=>{}, '1600':()=>{},'default':()=>{}}
     * @param {Number} screenResolution 屏幕分辨率  默认值 window['globalData'].screenInfo.screenResolution
     */
    menuSizeHandle(BKInfo,screenResolution){
      const tempscreenResolution = screenResolution ||  window['globalData'].screenInfo.screenResolution
      const tempKeyList = Object.keys(BKInfo)
      const defaultFC = tempKeyList.filter(key => key !='default')
      const tempKey = defaultFC.sort((a, b) => a - b)
      // console.log('key==>',tempKey, tempscreenResolution);
      let isExecuteFun = false
      for(let i = 0; i< tempKey.length; i++){
        const keyMin = tempKey[i]
        let keyMax  = tempKey[i+1]
        if(!keyMax){
          if(keyMin<=tempscreenResolution){
            BKInfo[keyMin]()
            isExecuteFun = true
            break
          }
        } else {
          if(keyMin<=tempscreenResolution && tempscreenResolution< keyMax){
            BKInfo[keyMin]()
            isExecuteFun = true
            break
          }
        }
      }
      // console.log('key==>',tempKey, tempscreenResolution, isExecuteFun);
      if(!isExecuteFun){
        BKInfo['default'] && BKInfo['default']()
      }
    }
  }
}
